package com.berchen.数据结构.哈希表;


/**
 * 链表
 */
public class EmpLinkedList {

    private Emp head;
    public void add(Emp emp){
        if(head==null){
            head=emp;
        }
        else {
            Emp temp=head;
            while (temp!=null){
                temp=temp.next;
            }
            temp.next=emp;
        }
    }

    public void list(int i){
        if(head==null){
            System.out.println("第 "+(i+1)+" 链表为null");
        }
        else{
            System.out.print("第 "+(i+1)+" 链表为 => ");
            Emp temp=head;
            while (temp!=null){
                System.out.print(temp+" => ");
                temp=temp.next;
            }
            System.out.println();
        }
    }
    public Emp select(int id ){
        if(head==null){
            return null;
        }
        else {
            Emp temp=head;
            while (temp!=null){
                if(temp.getId()==id){
                    break;
                }
                else {
                    temp=temp.next;
                }
            }
            return temp;
        }
    }

}
